package com.zoshine.zzg.pojo.pojostatus;

import com.zoshine.zzg.base.Status;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 监所与供应商关系状态枚举，
 *
 * @author 田沛凌
 * @time 2017/7/7 21:56
 */
public enum RelationSupplierPrisonStatus {
    TOBE_AUDITED(0, "待审核"),
    AUDITED(1, "审核通过"),
    AUDITED_FAIL(9, "审核失败"),
    OVERDUE(99, "已过期"),
    ;

    private int value;
    private String desc;

    RelationSupplierPrisonStatus(final int value, final String desc) {
        this.value = value;
        this.desc = desc;
    }

    public int getValue() {
        return value;
    }

    public static String getDesc(Integer value) {
        for (RelationSupplierPrisonStatus commonStatus : RelationSupplierPrisonStatus.values()) {
            if (Objects.equals(value, commonStatus.value)) {
                return commonStatus.desc;
            }
        }
        return null;
    }

    // 缓存一个列表，防止每次使用都进行循环
    private static List<Status> statusList;
    public static List<Status> getList() {
        if (statusList == null || statusList.size() == 0) {
            statusList = new ArrayList<>();
            for (RelationSupplierPrisonStatus commonStatus : RelationSupplierPrisonStatus.values()) {
                // 将状态存入列表
                Status status = new Status();
                status.setValue(commonStatus.value);
                status.setDesc(commonStatus.desc);
                statusList.add(status);
            }
        }
        return statusList;
    }
}
